home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / IBM VisualAge for Java Enterprise v4.0 Retail / ivj40 / setup / IDE.Cab / F88149_ObjectConstructorPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-03-22  |  10.2 KB  |  374 lines

  1. package com.ibm.ivj.testpilot.view.swing;
  2.  
  3. import com.ibm.ivj.testpilot.control.MemberControlEvent;
  4. import com.ibm.ivj.testpilot.control.MemberController;
  5. import com.ibm.ivj.testpilot.model.FactoryModel;
  6. import com.ibm.ivj.testpilot.model.MemberModel;
  7. import com.ibm.ivj.testpilot.model.TypeConstructorModel;
  8. import com.ibm.ivj.testpilot.utils.ClassUtils;
  9. import com.ibm.ivj.testpilot.view.MembersViewEventListener;
  10. import com.ibm.ivj.testpilot.view.swing.list.ObjectListEventListener;
  11. import java.awt.BorderLayout;
  12. import java.awt.Container;
  13. import java.awt.Frame;
  14. import javax.swing.BorderFactory;
  15. import javax.swing.Icon;
  16. import javax.swing.JButton;
  17. import javax.swing.JLabel;
  18. import javax.swing.JOptionPane;
  19. import javax.swing.JPanel;
  20. import javax.swing.JSplitPane;
  21. import javax.swing.JTabbedPane;
  22.  
  23. public class ObjectConstructorPanel extends MembersPanel {
  24.    private static String copyright = "Licensed Material - Property of IBM IBM(R) VisualAge(R) for Java(TM), Version 3.5 (C) Copyright IBM Corp. 1997, 2000- All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.";
  25.    private Class targetType = null;
  26.    private JSplitPane splitPane = null;
  27.    private JTabbedPane tabbedPane = null;
  28.    private JPanel constructorsPanel = null;
  29.    private JPanel staticsPanel = null;
  30.    private TreeSplitPanel constructorsSplitPanel = null;
  31.    private TreeSplitPanel staticsSplitPanel = null;
  32.    private ObjectListPanel objectListPanel = null;
  33.    private JPanel constructorsHeaderPanel = null;
  34.    private JPanel staticsHeaderPanel = null;
  35.    private JLabel constructorsInLabel = null;
  36.    private JLabel staticsInLabel = null;
  37.    private JButton constructorsInChangeButton = null;
  38.    private JButton staticsInChangeButton = null;
  39.    private static final String constructorsText = ResourceHandler.getHandler().getMessage("CONSTRUCTORS");
  40.    private static final String staticsText = ResourceHandler.getHandler().getMessage("FACTORY_METHODS");
  41.    private static final String argumentsText = ResourceHandler.getHandler().getMessage("ARGUMENTS");
  42.    private static final String inText = ResourceHandler.getHandler().getMessage("IN");
  43.    private static final String changeText = ResourceHandler.getHandler().getMessage("CHANGE");
  44.    private static final String classInputTitle = ResourceHandler.getHandler().getMessage("CLASS_INPUT_TITLE");
  45.    private static final String constructorChangeMsg = ResourceHandler.getHandler().getMessage("CONSTRUCTOR_CHANGE_MSG");
  46.    private static final String factoryChangeMsg = ResourceHandler.getHandler().getMessage("FACTORY_CHANGE_MSG");
  47.    private static final String changeClassErrorTitle = ResourceHandler.getHandler().getMessage("CLASS_INPUT_ERROR_TITLE");
  48.    // $FF: synthetic field
  49.    static Class class$0;
  50.  
  51.    public ObjectConstructorPanel(Class var1) {
  52.       this.initializeType(var1);
  53.       this.initialize();
  54.    }
  55.  
  56.    public ObjectConstructorPanel(Class var1, Frame var2) {
  57.       ((MembersPanel)this).setRootFrame(var2);
  58.       this.initializeType(var1);
  59.       this.initialize();
  60.    }
  61.  
  62.    public void addMembersViewEventListener(MembersViewEventListener var1) {
  63.       this.getConstructorsSplitPanel().addMembersViewEventListener(var1);
  64.       this.getStaticsSplitPanel().addMembersViewEventListener(var1);
  65.    }
  66.  
  67.    public void addObjectListEventListener(ObjectListEventListener var1) {
  68.       this.getObjectListPanel().addObjectListEventListener(var1);
  69.    }
  70.  
  71.    public void cleanup() {
  72.    }
  73.  
  74.    private Class defaultPromptForType(String var1, String var2, Class var3) {
  75.       Frame var4 = ((MembersPanel)this).getRootFrame();
  76.       Class var5 = null;
  77.       String var6 = var2;
  78.       if (var2 == null) {
  79.          var6 = "";
  80.       }
  81.  
  82.       Class var7 = var3;
  83.       if (var3 == null) {
  84.          Class var10000 = class$0;
  85.          if (var10000 == null) {
  86.             try {
  87.                var10000 = Class.forName("java.lang.Object");
  88.             } catch (ClassNotFoundException var14) {
  89.                throw new NoClassDefFoundError(((Throwable)var14).getMessage());
  90.             }
  91.  
  92.             class$0 = var10000;
  93.          }
  94.  
  95.          var7 = var10000;
  96.       }
  97.  
  98.       boolean var8 = false;
  99.       Object var9 = null;
  100.       String var10 = "";
  101.       Object var11 = null;
  102.  
  103.       while(!var8) {
  104.          var9 = JOptionPane.showInputDialog(var4, var1, classInputTitle, 3, (Icon)null, (Object[])null, var6);
  105.          if (var9 == null) {
  106.             var8 = true;
  107.          } else {
  108.             var10 = "" + var9.toString();
  109.             Class var17 = null;
  110.             var6 = var10;
  111.  
  112.             try {
  113.                var17 = Class.forName(var10);
  114.             } catch (Throwable var13) {
  115.                JOptionPane.showMessageDialog(var4, "" + var13, changeClassErrorTitle, 0);
  116.             }
  117.  
  118.             if (var17 != null) {
  119.                if (var7.isAssignableFrom(var17)) {
  120.                   var5 = var17;
  121.                   var8 = true;
  122.                } else {
  123.                   JOptionPane.showMessageDialog(var4, ResourceHandler.getHandler().getMessage("CLASS_ASSIGN_ERROR", var10, var3.getName()), changeClassErrorTitle, 0);
  124.                }
  125.             }
  126.          }
  127.       }
  128.  
  129.       return var5;
  130.    }
  131.  
  132.    private Class getClassFromUser(String var1, String var2, Class var3) {
  133.       return !MemberController.getVmAllowsClassPrompting() ? this.defaultPromptForType(var1, var2, var3) : this.defaultPromptForType(var1, var2, var3);
  134.    }
  135.  
  136.    private JPanel getConstructorsHeaderPanel() {
  137.       if (this.constructorsHeaderPanel == null) {
  138.          this.constructorsHeaderPanel = new JPanel(new BorderLayout());
  139.          this.constructorsHeaderPanel.add(this.getConstructorsInLabel(), "Center");
  140.          this.constructorsHeaderPanel.add(this.getConstructorsInChangeButton(), "East");
  141.          this.constructorsHeaderPanel.setBorder(BorderFactory.createEtchedBorder());
  142.       }
  143.  
  144.       return this.constructorsHeaderPanel;
  145.    }
  146.  
  147.    private JButton getConstructorsInChangeButton() {
  148.       if (this.constructorsInChangeButton == null) {
  149.          this.constructorsInChangeButton = new JButton(changeText);
  150.          this.constructorsInChangeButton.addActionListener(new 1(this));
  151.       }
  152.  
  153.       return this.constructorsInChangeButton;
  154.    }
  155.  
  156.    private JLabel getConstructorsInLabel() {
  157.       if (this.constructorsInLabel == null) {
  158.          String var1 = ClassUtils.getLongNameFor(this.getTargetType());
  159.          this.constructorsInLabel = new JLabel(constructorsText + " " + inText + " " + var1);
  160.          this.constructorsInLabel.setHorizontalAlignment(0);
  161.       }
  162.  
  163.       return this.constructorsInLabel;
  164.    }
  165.  
  166.    private JPanel getConstructorsPanel() {
  167.       if (this.constructorsPanel == null) {
  168.          this.constructorsPanel = new JPanel(new BorderLayout());
  169.          this.constructorsPanel.add(this.getConstructorsHeaderPanel(), "North");
  170.          this.constructorsPanel.add(this.getConstructorsSplitPanel(), "Center");
  171.       }
  172.  
  173.       return this.constructorsPanel;
  174.    }
  175.  
  176.    private TreeSplitPanel getConstructorsSplitPanel() {
  177.       if (this.constructorsSplitPanel == null) {
  178.          this.constructorsSplitPanel = new TreeSplitPanel(new TypeConstructorModel(this.getTargetType()), constructorsText, argumentsText);
  179.          this.constructorsSplitPanel.addMemberControlEventListener(new 2(this));
  180.       }
  181.  
  182.       return this.constructorsSplitPanel;
  183.    }
  184.  
  185.    public MemberController getInvokeTarget() {
  186.       switch (this.getTabbedPane().getSelectedIndex()) {
  187.          case 0:
  188.             return this.getConstructorsSplitPanel().getInvokeTarget();
  189.          case 1:
  190.             return this.getStaticsSplitPanel().getInvokeTarget();
  191.          default:
  192.             return null;
  193.       }
  194.    }
  195.  
  196.    public Object getNewObject() {
  197.       return this.getObjectListPanel().getSelectedObject();
  198.    }
  199.  
  200.    private ObjectListPanel getObjectListPanel() {
  201.       if (this.objectListPanel == null) {
  202.          this.objectListPanel = new ObjectListPanel();
  203.       }
  204.  
  205.       return this.objectListPanel;
  206.    }
  207.  
  208.    public MemberController getSelectedController() {
  209.       switch (this.getTabbedPane().getSelectedIndex()) {
  210.          case 0:
  211.             return this.getConstructorsSplitPanel().getSelectedController();
  212.          case 1:
  213.             return this.getStaticsSplitPanel().getSelectedController();
  214.          default:
  215.             return null;
  216.       }
  217.    }
  218.  
  219.    private JSplitPane getSplitPane() {
  220.       if (this.splitPane == null) {
  221.          this.splitPane = new MySplitPane(0);
  222.          this.splitPane.setTopComponent(this.getTabbedPane());
  223.          this.splitPane.setBottomComponent(this.getObjectListPanel());
  224.          this.splitPane.setDividerLocation((double)0.75F);
  225.       }
  226.  
  227.       return this.splitPane;
  228.    }
  229.  
  230.    private JPanel getStaticsHeaderPanel() {
  231.       if (this.staticsHeaderPanel == null) {
  232.          this.staticsHeaderPanel = new JPanel(new BorderLayout());
  233.          this.staticsHeaderPanel.add(this.getStaticsInLabel(), "Center");
  234.          this.staticsHeaderPanel.add(this.getStaticsInChangeButton(), "East");
  235.          this.staticsHeaderPanel.setBorder(BorderFactory.createEtchedBorder());
  236.       }
  237.  
  238.       return this.staticsHeaderPanel;
  239.    }
  240.  
  241.    private JButton getStaticsInChangeButton() {
  242.       if (this.staticsInChangeButton == null) {
  243.          this.staticsInChangeButton = new JButton(changeText);
  244.          this.staticsInChangeButton.addActionListener(new 3(this));
  245.       }
  246.  
  247.       return this.staticsInChangeButton;
  248.    }
  249.  
  250.    private JLabel getStaticsInLabel() {
  251.       if (this.staticsInLabel == null) {
  252.          String var1 = ClassUtils.getLongNameFor(this.getTargetType());
  253.          this.staticsInLabel = new JLabel(staticsText + " " + inText + " " + var1);
  254.          this.staticsInLabel.setHorizontalAlignment(0);
  255.       }
  256.  
  257.       return this.staticsInLabel;
  258.    }
  259.  
  260.    private JPanel getStaticsPanel() {
  261.       if (this.staticsPanel == null) {
  262.          this.staticsPanel = new JPanel(new BorderLayout());
  263.          this.staticsPanel.add(this.getStaticsHeaderPanel(), "North");
  264.          this.staticsPanel.add(this.getStaticsSplitPanel(), "Center");
  265.       }
  266.  
  267.       return this.staticsPanel;
  268.    }
  269.  
  270.    private TreeSplitPanel getStaticsSplitPanel() {
  271.       if (this.staticsSplitPanel == null) {
  272.          this.staticsSplitPanel = new TreeSplitPanel(new FactoryModel(this.getTargetType()), staticsText, argumentsText);
  273.          this.staticsSplitPanel.addMemberControlEventListener(new 4(this));
  274.       }
  275.  
  276.       return this.staticsSplitPanel;
  277.    }
  278.  
  279.    private JTabbedPane getTabbedPane() {
  280.       if (this.tabbedPane == null) {
  281.          this.tabbedPane = new JTabbedPane();
  282.          this.tabbedPane.add(constructorsText, this.getConstructorsPanel());
  283.          this.tabbedPane.add(staticsText, this.getStaticsPanel());
  284.       }
  285.  
  286.       return this.tabbedPane;
  287.    }
  288.  
  289.    public Class getTargetType() {
  290.       if (this.targetType == null) {
  291.          Class var10001 = class$0;
  292.          if (var10001 == null) {
  293.             try {
  294.                var10001 = Class.forName("java.lang.Object");
  295.             } catch (ClassNotFoundException var1) {
  296.                throw new NoClassDefFoundError(((Throwable)var1).getMessage());
  297.             }
  298.  
  299.             class$0 = var10001;
  300.          }
  301.  
  302.          this.targetType = var10001;
  303.       }
  304.  
  305.       return this.targetType;
  306.    }
  307.  
  308.    private void handleConstructorClassChange() {
  309.       Class var1 = this.getTargetType();
  310.       Class var2 = this.getClassFromUser(constructorChangeMsg, var1.getName(), var1);
  311.       if (var2 != null && !var2.equals(var1)) {
  312.          this.getConstructorsSplitPanel().replaceModel(new TypeConstructorModel(var2));
  313.          this.getConstructorsSplitPanel().getTree().setSelectionRow(1);
  314.          this.getConstructorsInLabel().setText(constructorsText + " " + inText + " " + ClassUtils.getLongNameFor(var2));
  315.       }
  316.    }
  317.  
  318.    private void handleNewInstanceEvent(MemberControlEvent var1) {
  319.       if (var1 != null) {
  320.          Object var2 = var1.getResultObject();
  321.          if (var2 != null) {
  322.             this.getObjectListPanel().addObject(var2);
  323.          }
  324.       }
  325.    }
  326.  
  327.    private void handleStaticsClassChange() {
  328.       Class var1 = this.getTargetType();
  329.       Class var2 = this.getStaticsSplitPanel().getRootController().getModel().getActualType();
  330.       Class var3 = this.getClassFromUser(factoryChangeMsg, var2.getName(), (Class)null);
  331.       if (var3 != null && !var3.equals(var2)) {
  332.          this.getStaticsSplitPanel().replaceModel(new FactoryModel(var3, var1));
  333.          this.getStaticsSplitPanel().getTree().setSelectionRow(1);
  334.          this.getStaticsInLabel().setText(staticsText + " " + inText + " " + ClassUtils.getLongNameFor(var3));
  335.       }
  336.    }
  337.  
  338.    private void initialize() {
  339.       ((Container)this).setLayout(new BorderLayout());
  340.       ((Container)this).add(this.getSplitPane(), "Center");
  341.    }
  342.  
  343.    private void initializeType(Class var1) {
  344.       this.targetType = var1;
  345.    }
  346.  
  347.    public void removeObjectListEventListener(ObjectListEventListener var1) {
  348.       this.getObjectListPanel().removeObjectListEventListener(var1);
  349.    }
  350.  
  351.    public void replaceModel(MemberModel var1) {
  352.       this.getConstructorsSplitPanel().replaceModel(var1);
  353.    }
  354.  
  355.    private Class vajPromptForType(String var1, String var2, Class var3) {
  356.       return null;
  357.    }
  358.  
  359.    // $FF: synthetic method
  360.    static void access$0(ObjectConstructorPanel var0) {
  361.       var0.handleConstructorClassChange();
  362.    }
  363.  
  364.    // $FF: synthetic method
  365.    static void access$1(ObjectConstructorPanel var0, MemberControlEvent var1) {
  366.       var0.handleNewInstanceEvent(var1);
  367.    }
  368.  
  369.    // $FF: synthetic method
  370.    static void access$2(ObjectConstructorPanel var0) {
  371.       var0.handleStaticsClassChange();
  372.    }
  373. }
  374.